//index.js
//获取应用实例
const app = getApp()

Page({
	data: {
		detail: {
			title: "获取中...",
			content: "获取中..."
		},
		index: null,
		is_liked: false
	},

	onLoad: function(op) {
		let that = this
		wx.showLoading({
			title: "加载中..."
		})
		app.httpGet("mail/getSharingLetter", {
			user_id: op.user_id,
			letter_id: op.letter_id
		}, function(res) {
			wx.hideLoading();
			if (res.status == 1) {
				that.setData({
					detail: res.info
				})
			} else if (res.status == 0) {
				wx.showToast({
					icon: "none",
					title: res.msg
				})
			} else {
				wx.showToast({
					icon: "none",
					title: "服务器出错，请上报开发者"
				})
			}
		})
	},
	likeLetter() {
		let that = this
		app.httpGet('mail/likeThisLetter', {
			letter_id: that.data.detail.id,
			user_id: app.globalData.dbInfo.id
		}, function(res) {
			if (res.status == 1) {
				var detail = that.data.detail
				detail.like_num = res.like_num
				that.setData({
					is_liked: true,
					detail: detail
				})
			} else if (res.status == 0) {
				wx.showToast({
					title: res.msg,
					icon: "none"
				})
				that.setData({
					is_liked: true
				})
			} else {
				wx.showToast({
					title: "服务器异常，请上报开发者！",
					icon: "none"
				})
			}
		})
	},
	secondLike() {

	},
	toWrite(){
		wx.navigateTo({
			url:"/pages/write/write"
		})
	},
	toPublic(){
		wx.redirectTo({
			url:"/pages/public/index/index"
		})
	}

})
